﻿using System;
using System.Collections.Generic;
using System.Text;
using StockTrader.BusinessService.DataContract.Mortgate;
using StockTrader.FrontEnd.DataContract;

namespace Mortgage.DDL
{
    public class AssetUI
    {
        public decimal PorfolioTradingStockValue { set; get; }
        public decimal T0BoughtStockValue { set; get; }
        public decimal T1BoughtStockValue { set; get; }
        public decimal T2BoughtStockValue { set; get; }
        public decimal T3BoughtStockValue { set; get; }
        public decimal SoldAmount { set; get; }
        public decimal BoughtAmount { set; get; }

        public decimal AssetAmount { set; get; }
        public decimal StockAmount { set; get; }
        public decimal CashAmount { set; get; }
        public decimal NettingAmount { set; get; }
        public decimal BlockAmount { set; get; }
        public decimal TradingAmount { set; get; }
        public decimal PreLoan { set; get; }

        public List<OrderUI> T0TradingHist;
        public List<OrderUI> T0Trading;
        public List<StocksData> T0;
        public List<StocksData> T1;
        public List<StocksData> T2;
        public List<StocksData> T3;

        public decimal TotalT2Needed;
        public decimal TotalCashNeeded;

        public AssetUI() { }

        public AssetUI(decimal portfo, decimal t0, decimal t1, decimal t2, decimal t3, decimal sold, decimal bought, decimal asset, decimal stocks, decimal cash, decimal netting, decimal block, decimal trading, decimal loan, List<OrderUI> t0tradingdata, List<StocksData> t0data, List<StocksData> t1data, List<StocksData> t2data, List<StocksData> t3data, List<OrderUI> T0Hist, decimal totalt2needed, decimal totalcashneeded )
        {
            PorfolioTradingStockValue = portfo;
            T0BoughtStockValue = t0;
            T1BoughtStockValue = t1;
            T2BoughtStockValue = t2;
            T3BoughtStockValue = t3;
            SoldAmount = sold;
            BoughtAmount = bought;
            AssetAmount = asset;
            StockAmount = stocks;
            CashAmount = cash;
            NettingAmount = netting;
            BlockAmount = block;
            TradingAmount = trading;
            PreLoan = loan;

            T0Trading = t0tradingdata;
            T0 = t0data;
            T1 = t1data;
            T2 = t2data;
            T3 = t3data;
            T0Hist = T0Hist;
            TotalT2Needed = totalt2needed;
            TotalCashNeeded = totalcashneeded;
        }

        public List<StocksData> getStockHolding()
        {
            List<StocksData> list = new List<StocksData>();

            foreach (StocksData stock in T0)
                if (stock.Quantity > 100)
                    list.Add(stock);
            foreach (StocksData stock in T1)
                if (stock.Quantity > 100)
                    list.Add(stock);
            foreach (StocksData stock in T2)
                if (stock.Quantity > 100)
                    list.Add(stock);
            foreach (StocksData stock in T3)
                if (stock.Quantity > 100)
                    list.Add(stock);

            list.Sort(delegate(StocksData stock1, StocksData stock2)
            {
                int settlement = stock1.TillSettlement.CompareTo(stock2.TillSettlement);
                if (settlement.Equals(0))
                    return stock2.Quantity.CompareTo(stock1.Quantity);
                else
                    return settlement;
            });

            return list;
        }
    }
}
